<?php
class MyKVClient extends SaeKVClient
{
	private $_inited = false;
	/*
	
	*/
	public function init()
	{
		$_inited = true;
		return parent::init();
	}
	public function set($k, $v=null, $timeout = 0)
	{
		if(!$_inited)
		{
			$this->init();
		}
		if(!empty($timeout))
		{
			$timeout = time()+$timeout;
		}
		$v = array('d'=>$v,'t'=>$timeout);
		return parent::set($k,$v);
	}
	public function get($k)
	{
		if(!$_inited)
		{
			$this->init();
		}
		$v = parent::get($k);
		if($v['t']<time() && !empty($v['t']))
		{
			$this->delete($k);
			return false;
		}
		return $v['d'];
	}
	public function delete($k)
	{
		if(!$_inited)
		{
			$this->init();
		}
		return parent::delete($k);
	}
	public function mget($ks)
	{
		if(!$_inited)
		{
			$this->init();
		}
		$v = parent::mget($ks);
		if(!empty($v))
		{
			foreach($v as $key=>$val)
			{
				if($val['t']<time() && !empty($val['t']))
				{
					unset($v[$key]);
					$this->delete($key);
				}
				else
				{
					$v[$key] = $val['d'];
				}
			}
		}
		return $v;
	}
	public function pkrget($k,$c=1)
	{
		if(!$_inited)
		{
			$this->init();
		}
		$v = parent::pkrget($k,$c);
		if(!empty($v))
		{
			foreach($v as $key=>$val)
			{
				if($val['t']<time() && !empty($val['t']))
				{
					unset($v[$key]);
					$this->delete($key);
				}
				else
				{
					$v[$key] = $val['d'];
				}
			}
		}
		return $v;
	}
}